﻿using System;
using System.Web;
using System.Xml;
using System.Collections;
using System.Configuration;

namespace TerryDong.Core
{
    public static class AppContext
    {
        public static string AppPath = null;            //such as C:\VS2005\Dang\xxx\
        public static string AppName = null;            //such as Dang.Web (WebApplication) or MyApp.exe (win exe)
        public static readonly DateTime DateMinValue = DateTime.Parse("1900-1-1");
        public static readonly DateTime DateMaxValue = DateTime.Parse("2099-12-31");
        public static string AppUrlPrefix = null;   //such as http://localhost

        static AppContext()
        {
            #region static initial

            HttpContext pageContext = HttpContext.Current;
            if (pageContext == null)//windows or console application
            {
                AppDomain domain = AppDomain.CurrentDomain;
                AppPath = domain.BaseDirectory;
                AppName = domain.FriendlyName;

            }
            else //web application
            {
                HttpRequest request = pageContext.Request;
                AppPath = request.PhysicalApplicationPath;
                AppName = request.ApplicationPath.Substring(1);
                AppUrlPrefix = string.Format("http://{0}", request.ServerVariables["HTTP_HOST"]);
            }

            #endregion
        }
    }
}
